#coding=utf-8

import xadmin
import xadmin.views as xviews
from django.core import urlresolvers
from .models import *
from xadmin.layout import Main, TabHolder, Tab, Fieldset, Row, Col, AppendedText, Side

#后台主题
class BaseSetting(object):
    enable_themes = True
    use_bootswatch = True
xadmin.site.register(xviews.BaseAdminView, BaseSetting)

#
class AdminSettings(object):
    # 设置base_site.html的Title
    site_title = 'CMS'
    # 设置base_site.html的 Footer  页脚
    site_footer = 'Winhong Inc.'
    menu_style = 'default'

xadmin.site.register(xviews.CommAdminView, AdminSettings)
    #菜单设置
    # def get_site_menu(self):
    #     return (
    #         {'title': '博客管理', 'perm': self.get_model_perm(Page, 'change'), 'menus': (
    #             {'title': '所有页面', 'icon': 'fa fa-vimeo-square'
    #                 , 'url': self.get_model_url(Page, 'changelist')},
    #             {'title': '分类目录', 'icon': 'fa fa-vimeo-square'
    #                 , 'url': self.get_model_url(Category, 'changelist')},
    #         )},
    #     )
#xadmin.site.register(xviews, AdminSettings)

# class GlobalSetting(object):
#       #菜单设置
#      def get_site_menu(self):
#          return (
#              {'title': '投票管理', 'perm': self.get_model_perm(Poll, 'change'), 'menus':(
#                  {'title': '投票',  'url': self.get_model_url(Poll, 'changelist')},
#                  {'title':'选票','url': self.get_model_url(Choice, 'changelist')}
#              )},
#          )
# xadmin.site.register(views.CommAdminView, GlobalSetting)





class ColumnAdmin(object):
    search_fields = ('name', 'intro')
    fields = ('name', 'intro')
    ordering = ('-id', )
    save_on_top = True

    def preview(self, obj):
        url_edit = urlresolvers.reverse('admin:blog_post_change', args=(obj.id,))
        return u'''
                    <span><a href="/%s.html" target="_blank">预览</a></span>
                    <span><a href="%s" target="_blank">编辑</a></span>
                ''' % (obj.alias, url_edit)
    preview.short_description = u'操作'
    preview.allow_tags = True

xadmin.site.register(Column, ColumnAdmin)


class AuthorAdmin(object):
    search_fields = ('name')
    fields = ('id', 'name', 'password' )
    list_display = ('id', 'name', 'password' )   # 定义列表中显示的字段
    #save_on_top = True
    
xadmin.site.register(Author, AuthorAdmin)

#文章
class ArticleAdmin(object):
    search_fields = ('title')
    #fields = ('id', 'name', 'password' )
    list_display = ('id', 'title', 'content' )   # 定义列表中显示的字段

xadmin.site.register(Article, ArticleAdmin)

#图片
class ImgAdmin(object):
    search_fields = ('title')
    list_display = ('id', 'title', 'img_name' )

xadmin.site.register(Img, ImgAdmin)

